//
//  IMClientHttp.h
//  IMSecurityDemo
//
//  Created by zhangfan on 2020/6/8.
//  Copyright © 2020 zhangfan. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface IMClientHttp : NSObject

/**
 初始化连接对象
 
 @param serverCerts 服务端证书列表（base64编码字符串或证书文件路径）
 @param clientEncCert 客户端加密证书(base64编码字符串或证书文件路径)
 @param clientEncKey 客户端加密证书私钥(base64编码字符串或证书文件路径)
 @param clientSignCert 客户端签名证书(base64编码字符串或证书文件路径)
 @param clientSignKey 客户端签名证书私钥(base64编码字符串或证书文件路径)
 @param keyPassword 私钥口令（加密证书与签名证书一致）
 @return 连接对象，失败时返回nil
 */
- (instancetype)initWithServerCerts:(NSArray *)serverCerts
                      clientEncCert:(NSString *)clientEncCert
                       clientEncKey:(NSString *)clientEncKey
                     clientSignCert:(NSString *)clientSignCert
                      clientSignKey:(NSString *)clientSignKey
                        keyPassword:(NSString *)keyPassword;

/**
 初始化连接对象
 
 @param serverCerts 服务端证书列表
 @param userName 用户名
 @param PIN 证书PIN码
 @param error 错误码
 @return https连接对象
 */
- (instancetype)initWithServerCerts:(NSArray *)serverCerts
                           userName:(NSString *)userName
                                PIN:(NSString *)PIN
                          errorCode:(int *)error;

- (void)setServerCerts:(NSArray *)serverCerts;

/**
 设置超时时间
 
 @param timeout 超时时间（单位：秒）
 */
- (void)setTimeOut:(NSTimeInterval)timeout;


- (void)setHeader:(NSDictionary *)header;

/**
 HTTPS POST请求
 
 @param urlString 服务接口地址
 @param parameters 参数
 @param success 成功后执行block
 @param failure 失败后执行Block
 */
- (void)postWithUrl:(NSString *)urlString
         parameters:(id)parameters
            success:(void(^)(id objResult))success
            failure:(void(^)(int errorCode,NSString* error))failure;

/**
 HTTP GET请求
 
 @param urlString 服务接口地址
 @param parameters 参数
 @param success 成功后执行block
 @param failure 失败后执行block
 */
- (void)getWithUrl:(NSString *)urlString
        parameters:(id)parameters
           success:(void(^)(id objResult))success
           failure:(void(^)(int errorCode,NSString* error))failure;



/// 数据内容上传
/// @param url 数据上传url
/// @param data 待上传的数据
/// @param success 完成后执行block
/// @param failure 失败后执行block
- (void)uploadWithURL:(NSString *)url
               NSData:(NSData *)data
              success:(void (^)(id responseObject))success
              failure:(void (^)(int errNo, NSString *errMsg))failure;


/// HTTP上传文件
/// @param url 文件上传地址
/// @param filePath  文件路径
/// @param progress 上传实时进度回调block
/// @param success 成功后执行block
/// @param failure 失败后执行block
- (void)uploadWithURL:(NSString *)url
             filePath:(NSString *)filePath
             progress:(nullable void (^)(long long totalSize, long long completeSize, float progValue))progress
              success:(void (^)(id responseObject))success
              failure:(void (^)(int errNo, NSString *errMsg))failure;

/**
 数据下载请求
 
 @param urlString 下载地址
 @param progress 实时进度回调block
 @param success 成功后执行block
 @param failure 失败后执行block
 */
- (void)downloadWithURL:(NSString *)urlString
               progress:(nullable void (^)(long long, long long, float))progress
                success:(void (^)(id responseObject))success
                failure:(void (^)(int errNo, NSString *errMsg))failure;


/// 文件下载
/// @param urlString 文件下载地址
/// @param filePath 文件存储路径
/// @param progress 实时进度显示回调block
/// @param success 完成后执行block
/// @param failure 失败后执行block
- (void)downloadWithURL:(NSString *)urlString
               filePath:(NSString *)filePath
               progress:(nullable void (^)(long long, long long, float))progress
                success:(void (^)(id responseObject))success
                failure:(void (^)(int errNo, NSString *errMsg))failure;

@end

NS_ASSUME_NONNULL_END
